package com.example.week10_spring_security.service;

import com.example.week10_spring_security.entity.User;
import com.example.week10_spring_security.repo.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserService {
    @Autowired
    UserRepo userRepo;

    @Cacheable(cacheNames = "user", key = "#name", condition = "#name!=null")
    public User getUser(String name) {
        Optional<User> u = userRepo.findById(name);
        return u.isPresent()?u.get():null;
    }
}
